package com.dycx.api.controller.manage.cms;

import com.dycx.cms.dto.LinkDTO;
import com.dycx.cms.service.LinkService;
import com.dycx.common.RestResponse;
import com.dycx.common.annotation.WriterLog;
import com.dycx.common.enums.BizTypeEnum;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


@RestController
@RequestMapping(value = "/manage/cms/link")
public class LinkController {

    @Resource
    private LinkService linkService;

    /**
     * 添加
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_ARTICLE, bizValue = "{#linkDto.id}",logTitle = "添加友情链接")
    @PostMapping("/add")
    public RestResponse<?> add(@RequestBody @Valid LinkDTO linkDto) {
        return linkService.add(linkDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 修改
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_ARTICLE, bizValue = "{#linkDto.id}",logTitle = "修改友情链接")
    @PostMapping("/edit")
    public RestResponse<?> edit(@RequestBody @Valid LinkDTO linkDto) {
        return linkService.edit(linkDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 刪除
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_ARTICLE, bizValue = "{#id}",logTitle = "刪除友情链接")
    @GetMapping("/delete")
    public RestResponse<?> delete(int id) {
        return linkService.delete(id) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 分页
     **/
    @PostMapping("/getPage")
    public RestResponse<?> getPage(@RequestBody LinkDTO linkDto) {
        return RestResponse.success(linkService.getPage(linkDto));
    }

    /**
     * 查询详细
     **/
    @GetMapping("/getDetailById")
    public RestResponse<?> getDetailById(int id) {
        return RestResponse.success(linkService.getDetailById(id, null));
    }

    /**
     * 修改排序
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_LINK, bizValue = "{#linkDTO.id}",logTitle = "添加友情链接")
    @PostMapping("/updateSort")
    public RestResponse<?> updateSort(@RequestBody LinkDTO linkDTO) {
        return RestResponse.success(linkService.updateSort(linkDTO));
    }

    /**
     * 修改状态
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_LINK, bizValue = "{#linkDTO.id}",logTitle = "更新友情链接排序")
    @PostMapping("/updateStatus")
    public RestResponse<?> updateStatus(@RequestBody LinkDTO linkDTO) {
        return RestResponse.success(linkService.updateStatus(linkDTO));
    }

}
